package cn.mybeky.douban.methods {
	import cn.mybeky.douban.Douban;
	import cn.mybeky.douban.events.DoubanResultEvent;
	
	import flash.events.Event;
	import flash.net.URLLoader;
	
	public class People {
		
		private var _douban:Douban;
		public function People(douban:Douban) {
			_douban = douban;
		}
		public function getInfo(userID:String):void {
			MethodsHelper.invokeMethod(_douban, 
			                           getInfo_result, 
			                           "douban.people.getInfo", 
			                           userID);
		}
		public function getUserTags(userID:String, category:String, startIndex:int=0, maxResults:int=10):void {
			var queryObj:Object = {"cat":category, 
			                       "start-index":startIndex, 
			                       "max-results":maxResults};
			                       
			MethodsHelper.invokeMethod(_douban, 
		                               getUserTags_result, 
		                               "douban.people.getUserTags", 
		                               userID, 
		                               queryObj);
            			
		}
		public function getUserCollection(userID:String, category:String, tag:String=null, status:String=null, startIndx:int=0, maxResults:int=10):void {
			var queryObj:Object = {"cat":category, 
			                       "tag":tag, 
			                       "status":status, 
			                       "start-index":startIndx, 
			                       "max-results":maxResults};
			                       
			MethodsHelper.invokeMethod(_douban, 
		                               getUserCollection_result, 
		                               "douban.people.getUserCollection", 
		                               userID, 
		                               queryObj);
		}
		
		
		private function getInfo_result(e:Event):void {
            var result:DoubanResultEvent = new DoubanResultEvent(DoubanResultEvent.PEOPLE_GET_INFO);

            MethodsHelper.processAndDispatch(_douban, 
                                             URLLoader(e.currentTarget).data, 
                                             result,
                                             "user",
                                             MethodsHelper.parseUser );
        }
        private function getUserTags_result(e:Event):void {
        	var result:DoubanResultEvent = new DoubanResultEvent(DoubanResultEvent.PEOPLE_GET_USER_TAGS);
        	MethodsHelper.processAndDispatch(_douban, 
                                             URLLoader(e.currentTarget).data, 
                                             result,
                                             "user",
                                             MethodsHelper.parseUserTags);
        }
        private function getUserCollection_result(e:Event):void {
        	var result:DoubanResultEvent = new DoubanResultEvent(DoubanResultEvent.PEOPLE_GET_USER_COLLECTION);
        	MethodsHelper.processAndDispatch(_douban, 
        	                                 URLLoader(e.currentTarget).data, 
        	                                 result, 
        	                                 "user",
        	                                 MethodsHelper.parseUserMovieCollection);
        }

	}
}